package com.hrm.service;

import com.hrm.dao.DepartmentDao;
import com.hrm.dao.PosDao;
import com.hrm.dto.Envelope;
import com.hrm.entity.DepartmentEntity;
import com.hrm.entity.PosEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by zekdot on 20-3-8.
 */
public class DepartmentService {

    private DepartmentDao departmentDao;

    private PosDao posDao;

    public DepartmentService(){
        departmentDao = new DepartmentDao();
        posDao = new PosDao();
    }

    /**
     * 获得所有部门
     * @return
     */
    public Envelope getAllDep(){
        List<String> res = new ArrayList();
        List<DepartmentEntity> list;
        try {
            list = departmentDao.getDepList();
        } catch (Exception e) {
            e.printStackTrace();
            return Envelope.dbError;
        }
        for(DepartmentEntity departmentEntity:list){
            res.add(departmentEntity.getName());
        }
        return new Envelope(res);
    }

    /**
     * 根据部门名称获取所有职位
     * @param dep
     * @return
     */
    public Envelope getPosByDep(String dep){
        List<String> res = new ArrayList();
        List<PosEntity> list;
        try{
            list = posDao.getListByDep(dep);
        }catch (Exception e){
            e.printStackTrace();
            return Envelope.dbError;
        }
        for(PosEntity posEntity:list){
            res.add(posEntity.getName());
        }
        return new Envelope(res);
    }
    public static void main(String args[]){
        DepartmentService departmentService = new DepartmentService();
        System.out.println(departmentService.getAllDep());
        System.out.println(departmentService.getPosByDep("指挥部"));
    }
}
